/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package gui.genomemap.outputModel;

import gui.genomemap.outputModel.options.ComGLHoodOOptionsModel;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToOne;

/**
 * the output model corresponding to the worker ComGLHood.
 * @author stewari1
 * @version 1.0
 * @updated 20-Nov-2007 7:37:55 PM
 */
@Entity
public class ComGLHoodOModel extends OutputModel implements java.io.Serializable {

    /** Field description */
    public static final int FIG_GMAP = 0;

    /**
     * the computed genetic likelihood
     */
    private double lHood = 0.0;

    /** Field description */
    private double pValue = 0.0;

    /** Field description */
    private double[] cProbInitial = null;

    /** Field description */
    private double[] cProbEst = null;

    /** Field description */
    private double[] recomArray = null;

    /** Field description */
    private double[] cellProbEst = null;

    /** Field description */
    private double[] seArray = null;

    /**
     * LHood worker attempts to compute the SE if <CODE>computingSE</CODE> is true in the
     * input model. If it succeeds(that is all the SEs are reportable) then only
     * <CODE>coputedSE</CODE> is set to <CODE>true</CODE> in the output model.
     */
    private boolean computedSE = false;

    /** Field description */
    private boolean computedPValue = false;

    /** Field description */
    @OneToOne(cascade = CascadeType.ALL)
    private ComGLHoodOOptionsModel optionsModel = new ComGLHoodOOptionsModel();

    /**
     * Constructs ...
     */
    public ComGLHoodOModel() {}

    /**
     * 3. higher lhood should come sooner. since TreeSet uses ascending..
     *   higher order should mean smaller.
     */
    @Override
    public int compareTo(OutputModel outputModel) {

        int superCompared = super.compareTo(outputModel);

        if ((superCompared == 0) && (outputModel instanceof ComGLHoodOModel)) {

            ComGLHoodOModel comGLHoodOModel = (ComGLHoodOModel) outputModel;
            double myLHood                  = getLHood();
            double hisLHood                 = comGLHoodOModel.getLHood();
            double diffLHood                = myLHood - hisLHood;

            return (int) ((-1.0) * diffLHood);
        }

        return superCompared;
    }

    @Override
    public int hashCode() {
        return super.hashCode() + new Double(getLHood()).hashCode();
    }

    @Override
    public boolean equals(Object obj) {

        if (obj instanceof ComGLHoodOModel) {

            ComGLHoodOModel comGLHoodOModel = (ComGLHoodOModel) obj;

            return super.equals(comGLHoodOModel) && (getLHood() == comGLHoodOModel.getLHood());
        }

        return false;
    }

    /**
     * the computed genetic likelihood
     */
    public double getLHood() {
        return lHood;
    }

    public void setLHood(double lHood) {
        this.lHood = lHood;
    }

    public boolean isComputedSE() {
        return computedSE;
    }

    public void setComputedSE(boolean computedSE) {
        this.computedSE = computedSE;
    }

    public boolean isComputedPValue() {
        return computedPValue;
    }

    public void setComputedPValue(boolean computedPValue) {
        this.computedPValue = computedPValue;
    }

    public double getPValue() {
        return pValue;
    }

    public void setPValue(double pValue) {
        this.pValue = pValue;
    }

    public double[] getCProbInitial() {
        return cProbInitial;
    }

    public void setCProbInitial(double[] cProbInitial) {
        this.cProbInitial = cProbInitial;
    }

    public double[] getCProbEst() {
        return cProbEst;
    }

    public void setCProbEst(double[] cProbEst) {
        this.cProbEst = cProbEst;
    }

    public double[] getCellProbEst() {
        return cellProbEst;
    }

    public void setCellProbEst(double[] cellProbEst) {
        this.cellProbEst = cellProbEst;
    }

    public double[] getRecomArray() {
        return recomArray;
    }

    public void setRecomArray(double[] recomArray) {
        this.recomArray = recomArray;
    }

    public double[] getSeArray() {
        return seArray;
    }

    public void setSeArray(double[] seArray) {
        this.seArray = seArray;
    }

    public ComGLHoodOOptionsModel getOptionsModel() {
        return optionsModel;
    }

    public void setOptionsModel(ComGLHoodOOptionsModel optionsModel) {
        this.optionsModel = optionsModel;
    }
}
